#!/bin/sh

# must not fail
set -e 

# debug
set -x 

echo "Starting $0"


MSCUSTOM_DISTNAME=mscustom_ejbca39.zip
MSCUSTOM_DIRNAME=mscustom_ejbca39
MSCUSTOM_SOFTLINK=mscustom
MSCUSTOM_UNPACKCMD=unzip


### copy to "install"

if [ ! -f ${DISTFILES_INSTALL}/${MSCUSTOM_DISTNAME} ] ; then 	
    echo "copying ${MSCUSTOM_DISTNAME} to ${DISTFILES_INSTALL}"
    cp ${MSCUSTOM_DISTNAME}     ${DISTFILES_INSTALL}
fi

### unpack if this version dont exist already
if [ -x ${INSTALL_INTO}/${MSCUSTOM_DIRNAME} ] ;then
    echo "${MSCUSTOM_DIRNAME} exists, skipping"
else

    cd ${INSTALL_INTO}
    ${MSCUSTOM_UNPACKCMD} ${DISTFILES_INSTALL}/${MSCUSTOM_DISTNAME} 
    cd -
fi


### soft links
rm -f ${MSCUSTOM_SOFTLINK}
ln -s ${MSCUSTOM_DIRNAME} ${INSTALL_INTO}/${MSCUSTOM_SOFTLINK}

### add to environment
echo "export MSCUSTOM_HOME=${INSTALL_INTO}/${MSCUSTOM_SOFTLINK}" >> ${INSTALL_INTO}/environment


### chmod
chown -R  ${appsrvuser}.${appsrvgrp} ${INSTALL_INTO}/${MSCUSTOM_DIRNAME}


echo "End of $0"


